﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Time.Model;

namespace Time.App
{
    public partial class Form1 : Form
    {
        private TimeDataContext db = new TimeDataContext();
        public Form1()
        {
            InitializeComponent();

            //ManageProjectWindow mpw = new ManageProjectWindow(this);
            //mpw.ShowDialog();

            //ManageModuleWindow mmw = new ManageModuleWindow(this);
            //mmw.ShowDialog();
        }

        private void createUserToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateUserWindow createUserWindow = new CreateUserWindow(this);
            DialogResult result = createUserWindow.ShowDialog();
            if (result == DialogResult.OK)
            {
                if (createUserWindow.User != null)
                {
                    MessageBox.Show(this, "User with e-mail address " + createUserWindow.User.EmailAddress + " created!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        private void signInToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SignInWindow signInWindow = new SignInWindow(this);
            DialogResult result = signInWindow.ShowDialog();
            if (result == DialogResult.OK)
            {
                //Program.User = signInWindow.User;
            }
        }

        private void signOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Program.User = null;
            MessageBox.Show(this, "Signed out!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void UpdateModules()
        {
            /*if (Program.User == null)
            {
                foreach (Control control in this.Controls)
                {
                    if (control.Tag != null) control.Enabled = false;
                }
                return;
            }

            List<UserModule> enabledUserModules = db.UserModules.Where(um => um.UserId == Program.User.Id).ToList();
            //List<Module> enabledModules = db.Modules.Where(m => m.Id 
            foreach (Control control in this.Controls)
            {
                string moduleName = control.Tag as string;
                if (moduleName == null) continue;
                //if (
            }*/
        }

        private void addToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            AddEditLicenseWindow aelw = new AddEditLicenseWindow(this);
            DialogResult result = aelw.ShowDialog();
            if (result == DialogResult.OK)
            {
                //Program.User = signInWindow.User;
            }
        }

        private void searchToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            FindLicenseWindow flw = new FindLicenseWindow(this);
            flw.ShowDialog();
        }
    }
}
